package com.example.module_service.car

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_common.view.view.BaseMvvmActivity
import com.example.module_service.R
import com.example.module_service.databinding.ActivityCarPayBinding
import com.example.module_service.entity.CarPayEntity
import com.example.module_service.entity.CarPayParam
import com.example.module_service.vm.CarPayViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@Route(path = "/car/CarPayActivity")
@AndroidEntryPoint
class CarPayActivity : BaseMvvmActivity<ActivityCarPayBinding>() {
    override fun getLayoutId(): Int =R.layout.activity_car_pay
    @Autowired
    @JvmField
    var carCode:String=""

    private val carPayViewModel: CarPayViewModel by  viewModels()
    override fun initViews() {
        ARouter.getInstance().inject(this)
        binding.carCode.text=carCode
        binding.carName.text=carCode
        binding.carTime1.text="月卡到期时间: "+SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis())
        binding.carTime2.text= SimpleDateFormat("2026-MM-dd HH:mm:ss").format(System.currentTimeMillis())

        binding.btnPayCar.setOnClickListener {
            var carPayParam= CarPayEntity(
                entryTime=SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                exitTime=SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                id=0,
                parkingDuration= 60,
                parkingSpaceNumber= "A10",
                paymentAmount= 45,
                paymentMethod= "1",
                paymentTime= SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()),
                paymentType= "1",
                plateNumber= carCode,
                reservationId= "1"
            )
            carPayViewModel.getCarPay(carPayParam)
        }
        carPayViewModel.mSuccessLiveData.observe(this){
            ToastUtils.showLong("缴费成功")
            ARouter.getInstance().build("/car/CarStopActivity").navigation()
        }
        carPayViewModel.mErrorLiveData.observe(this){
            ToastUtils.showLong(it)
        }
    }

    override fun getActivityState(state: Bundle) {
        TODO("Not yet implemented")
    }

    override fun saveActivityState(outState: Bundle) {
        TODO("Not yet implemented")
    }

}